home *** CD-ROM | disk | FTP | other *** search
/ 1,000+ Great Games / 1_1000 Games.iso / DOSGAMES / BOGGLE.ZIP / SOURCE.ZIP / OPTIONS.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1996-03-02  |  3.5 KB  |  90 lines

  1. /*****************************************************************************
  2. * Program:  OPTIONS.CPP
  3. * Purpose:  This module handles the support of the options/settings dialog 
  4. *           box that is in the system.
  5. *****************************************************************************/
  6. #include <os2.h>
  7. #include <icmdevt.hpp>                  //ICommandEvent
  8. #include <istring.hpp>                  //IString Class
  9. #include <ireslib.hpp>                  //IResourceLibrary/IResourceId Class
  10. #include <stdlib.h>
  11.  
  12. #include "options.h"                    
  13. #include "Aoptions.hpp"                 //AOptionsDialog Class
  14.  
  15. /*****************************************************************************
  16. * Function: AOptionsDialog
  17. * Parms:    ownerWnd - the owner of this window
  18. *           rid - ID of window in resource file
  19. *           pbwindow - a pointer to the TBogWindow class so we can check 
  20.             game options
  21. * Purpose:  Constructor for text dialog window
  22. * Returns:  Nothing
  23. *****************************************************************************/
  24. AOptionsDialog :: AOptionsDialog(IWindow * ownerWnd, unsigned long rid, TBogWindow* pbwindow)
  25.              : IFrameWindow(IResourceId(rid), ownerWnd)
  26. {
  27.    ICommandHandler::handleEventsFor(this); //Set self as command event handler
  28.    pbwin = pbwindow;
  29.  
  30. //define the entryfield so I can work with it
  31.    timerDuration = new IEntryField(sle_timerduration, this);
  32.    soundCheckBox = new ICheckBox(cb_sound, this);
  33.  
  34. // Get the number stored in the game variable and display it here.
  35.    IString ls_tickduration;
  36.    sprintf(ls_tickduration, "%.2f", pbwin->GetTickDuration() / 1000.00);   
  37.  
  38.    timerDuration->setText(ls_tickduration);
  39.  
  40. //Set the checkbox by what is set in the game
  41.    Boolean flag = pbwin->GetSoundFlag();
  42.    soundCheckBox->select(flag);
  43.  
  44. /*****************************************************************************
  45. * Function: ~AOptionsDialog
  46. * Parms:    None
  47. * Purpose:  Destructor - will delete instantiated items
  48. * Returns:  Nothing
  49. *****************************************************************************/
  50. AOptionsDialog :: ~AOptionsDialog()
  51. {
  52. //  ICommandHandler::stopHandlingEventsFor(this);  
  53.    delete timerDuration;
  54.    delete soundCheckBox;
  55.  
  56. /*****************************************************************************
  57. * Function: command
  58. * Parms:    cmdevt - info about what was selected in the window
  59. * Purpose:  Process Commands from the window
  60. * Returns:  true - if OK button was pressed,  false otherwise
  61. *****************************************************************************/
  62. Boolean AOptionsDialog :: command(ICommandEvent& cmdevt)
  63. {
  64.    //Get the value entered into the edit field and convert it to
  65.    // a number
  66.    float duration;
  67.    sscanf(timerDuration->text(), "%f", &duration);
  68.  
  69.    //Save the state of the checkBox
  70.    Boolean flag = soundCheckBox->isSelected();
  71.  
  72.    switch(cmdevt.commandId()) 
  73.    {
  74.    case DID_OK:
  75.       //We will set the number of milliseconds for the clock tick
  76.       // based on the number of seconds entered by the user.
  77.       pbwin->SetTickDuration(duration * 1000);
  78.  
  79.        //Save the value of the sound variable to the game
  80.        pbwin->SetSoundFlag(flag);
  81.  
  82.       dismiss(DID_OK);                 //Dismiss Dialog - Allow focus to main
  83.       return(true);                    //Return Processing Completed
  84.       break;
  85.  
  86.    }
  87.    return(false);                       //Allow Default Processing to occur
  88. }